package com.prd.controller;

import com.prd.model.EntContact;
import com.prd.model.EntContactReply;
import com.prd.service.EntContactReplyService;
import com.prd.service.EntContactService;
import com.prd.util.AjaxResult;
import com.prd.util.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "联络函(对内)")
@RestController
@RequestMapping("/api/entContact")
public class EntContactController extends BaseController {

    @Autowired
    private EntContactService entContactService;

    @Autowired
    private EntContactReplyService entContactReplyService;

    @ApiOperation("查询列表")
    @GetMapping("list")
    public TableDataInfo list(@ApiParam("日期") String day, @ApiParam("0：全部、1：我发起、2：我接收、3：我制单、4：待确认、5：已确认、6：待审批、7：审批通过、8：审批不通过") Integer catalog) {
        startPage();
        List<EntContact> list = entContactService.listInfo(day, catalog);
        return getDataPage(list);
    }

    @ApiOperation("添加信息")
    @PostMapping("add")
    public AjaxResult add(@RequestBody EntContact entContact) {
        return toAjax(entContactService.insertInfo(entContact));
    }

    @ApiOperation("修改信息")
    @PostMapping("update")
    public AjaxResult update(@RequestBody EntContact entContact) {
        return toAjax(entContactService.updateInfo(entContact));
    }

    @ApiOperation("查询详情")
    @GetMapping("details/{id}")
    public AjaxResult details(@PathVariable("id") Long id) {
        return AjaxResult.success(entContactService.details(id));
    }

    @ApiOperation("增加抄送人")
    @PostMapping(value = "addMake/{id}/{makes}")
    public AjaxResult addMake(@ApiParam("联络函ID") @PathVariable("id") Long id, @ApiParam("抄送人（多个,分开）") @PathVariable("makes") Long[] makes) {
        return toAjax(entContactService.addMake(id, makes));
    }

    @ApiOperation("添加收到回复/办结回复")
    @PostMapping("addContactReply")
    public AjaxResult addContactReply(@RequestBody EntContactReply entContactReply) {
        return AjaxResult.success(entContactReplyService.insertInfo(entContactReply));
    }

    @ApiOperation("撤回")
    @PostMapping("recall/{id}")
    public AjaxResult recall(@ApiParam("联络函ID") @PathVariable("id") Long id) {
        return AjaxResult.success(entContactService.recall(id));
    }
}
